package mysql

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	UserId  int     `gorm:"type:int;comment:用户id"`
	ClassId int     `gorm:"type:int;comment:课程id"`
	OrderSn string  `gorm:"type:varchar(40);comment:订单号"`
	Name    string  `gorm:"type:varchar(50);comment:课程名称"`
	Price   float64 `gorm:"type:decimal(10,2);comment:课程价格"`
	Cover   string  `gorm:"type:varchar(255);comment:课程封面"`
	Num     int     `gorm:"type:int;comment:购买数量"`
	Status  int     `gorm:"type:int;default:1;comment:订单状态:1-未支付，2-取消订单，3-已支付"`
	PayType int     `gorm:"type:int;default:1;comment:支付方式:1-支付宝，2-微信，3-银行卡"`
}

func (Order) TableName() string {
	return "order"
}

func (o *Order) Created() error {
	return DB.Create(&o).Error
}

func (o *Order) FindUpdated(Sn string, status int) error {
	return DB.Where("order_sn=?", Sn).Find(&o).Update("status", status).Error
}

func (o *Order) FindUpdated2(Sn string) error {
	return DB.Where("order_sn=?", Sn).Find(&o).Update("status", 2).Error
}
